import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_title_content_view.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/entities/application/smart_warehouse/product_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/smart_warehouse/warehouse_management/warehouse_details/warehouse_details_controller.dart';

/// 仓库详情页面
class WarehouseDetailsPage extends StatelessWidget {
  WarehouseDetailsPage({super.key});

  final controller = Get.put(WarehouseDetailsController());

  /// 获取仓库基础信息视图
  Widget _getBasicInformation() {
    return Container(
        height: 140.w,
        width: AppDimens.sh,
        padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.w),
        color: const Color(0xFF5C6DFF),
        child: Column(
          children: [
            Row(
              children: [
                SvgPicture.asset(
                  AppImages.icon_warehouse,
                  width: 17.w,
                  height: 17.w,
                ),
                AppGaps.hGap6,
                Expanded(
                    child: Text(
                  '仓库名称:${controller.warehouseEntity.warehouseName}',
                  style: TextStyle(
                    fontSize: 16.sp,
                    color: Colors.white,
                    overflow: TextOverflow.ellipsis,
                    fontWeight: FontWeight.w500,
                  ),
                )),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 9.w, vertical: 6.w),
                  decoration: BoxDecoration(
                    color: const Color(0x1Fffffff),
                    borderRadius: BorderRadius.circular(14.w),
                  ),
                  child: Text(
                    '出库记录',
                    style: TextStyle(
                      overflow: TextOverflow.ellipsis,
                      fontSize: 13.sp,
                      color: Colors.white,
                      fontWeight: FontWeight.w400,
                    ),
                  ),
                ).clickOnce(controller.toOutboundRecordsPage)
              ],
            ),
            AppGaps.vGap8,
            Row(
              children: [
                _getFieldView('面积:', '${controller.warehouseEntity.warehouseArea}㎡'),
                _getFieldView('储存量:', '${controller.warehouseEntity.warehouseStore}kg'),
              ],
            ),
            AppGaps.vGap10,
            Row(
              children: [
                _getFieldView('安全负责人:', '${controller.warehouseEntity.sadetyPersonName}'),
                _getFieldView('联系电话:', '${controller.warehouseEntity.responsibilityPhone}'),
              ],
            )
          ],
        ));
  }

  /// 字段显示
  Widget _getFieldView(String title, String value) {
    return Expanded(
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            title,
            style: TextStyle(
              fontSize: 13.sp,
              height: 1.2,
              color: const Color(0xFFFFFFFF),
              fontWeight: FontWeight.w400,
            ),
          ),
          Expanded(
              child: Text(
            value,
            style: TextStyle(
              fontSize: 13.sp,
              height: 1.2,
              color: const Color(0xFFFFFFFF),
              fontWeight: FontWeight.w400,
            ),
          ))
        ],
      ),
    );
  }

  /// 存储量列展示
  Widget _getCapacityView(ProductEntity item) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 14.w),
      decoration: BoxDecoration(
        color: const Color(0xFFF5F6FF),
        borderRadius: BorderRadius.all(
          Radius.circular(6.w),
        ),
      ),
      child: Row(
        children: [
          Container(
            color: const Color(0xff5C6DFF),
            width: 6.w,
            height: 6.w,
          ),
          AppGaps.hGap8,
          Expanded(
              child: Text(
            item.name!,
            style: TextStyle(
              fontSize: 14.sp,
              fontWeight: FontWeight.w500,
              color: const Color(0xff4D4D4D),
            ),
          )),
          SvgPicture.asset(
            AppImages.icon_product,
            width: 30.w,
            height: 30.w,
            // colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
          ),
          Text(
            item.inventory.toString(),
            style: TextStyle(
              fontSize: 16.sp,
              fontWeight: FontWeight.w500,
              color: const Color(0xff495061),
            ),
          ),
          Text(
            '件',
            style: TextStyle(
              fontSize: 12.sp,
              fontWeight: FontWeight.w500,
              color: const Color(0xff495061),
            ),
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            appBar: CustomAppBar(
              title: Text(
                '仓库详情',
                style: TextStyle(
                  fontSize: 18.sp,
                  color: Colors.white,
                  fontWeight: FontWeight.w400,
                ),
              ),
              leading: const BackButton(
                color: Colors.white,
              ),
              iconButtonColor: Colors.white,
              backgroundColor: const Color(0xFF5C6DFF),
            ),
            body: Container(
                color: const Color(0xFFF5F5F6),
                child: Stack(
                  children: [
                    // 仓库基础信息
                    _getBasicInformation(),
                    Container(
                      margin: EdgeInsets.only(top: 110.w),
                      padding: EdgeInsets.symmetric(horizontal: 16.w),
                      child: CustomTitleContentView(
                          title: Row(
                            children: [
                              SvgPicture.asset(
                                AppImages.icon_title,
                                width: 20.w,
                                height: 20.w,
                              ),
                              AppGaps.hGap10,
                              Text(
                                '产品储存量：共${controller.warehouseEntity.currentStorageCapacity}件',
                                style: TextStyle(
                                  fontSize: 15.sp,
                                  color: const Color(0xFF333333),
                                  fontWeight: FontWeight.w500,
                                ),
                              )
                            ],
                          ),
                          content: SizedBox(
                            height: AppDimens.sh - 300.w,
                            child: ListView.separated(
                                itemBuilder: (context, index) {
                                  return _getCapacityView(controller.productList[index]);
                                },
                                separatorBuilder: (context, index) => AppGaps.vGap16,
                                itemCount: controller.productList.length),
                          )),
                    )
                  ],
                )),
          );
        });
  }
}
